{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pdfplumber\n",
    "import pandas as pd\n",
    "pdf = pdfplumber.open(R\"C:/Users/YC111/Desktop/作业/bspdf.pdf\")\n",
    "table = []\n",
    "for i in range(len(pdf.pages)):\n",
    "   if(i+1)<len(pdf.pages):\n",
    "    page = pdf.pages[i + 1]\n",
    "    table.extend(page.extract_table())\n",
    "西北赛区推送国赛名单表 = pd.DataFrame(table,columns=('学校','项目名称','大类','参赛学生','指导教师'))\n",
    "西北赛区推送国赛名单表.loc[99]\n",
    "西北赛区推送国赛名单表.query('学校==\"西北民族大学\"')\n",
    "def get_works_amount_by_school(df, school:str)->int:\n",
    "    \"\"\" 按学校查询参赛学生作品数量\n",
    "    df: 国赛名单数据框\n",
    "    school：学校名称\n",
    "    返回值：该学校作品数量\"\"\"\n",
    "    return df.query(F'学校==\"{school}\"').shape[0]\n",
    "get_works_amount_by_school(西北赛区推送国赛名单表,'西北民族大学')\n",
    "get_works_amount_by_school(西北赛区推送国赛名单表,'兰州大学')\n",
    "get_works_amount_by_school(西北赛区推送国赛名单表,'西安建筑科技大学')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.10 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "09738f47427dba2c99ec68f9759744be2c477c434791ae3d2ff19909b29a18a8"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
